package com.example.demofdfs.web;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.management.RuntimeErrorException;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demofdfs.model.TestA;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;

@RestController
@Api
@RequestMapping("/test")
public class TestController extends BaseController{

	@ApiOperation(value = "add-testA")
	@ApiImplicitParam(name = "testA")
	@PostMapping("/testA")
	@ApiResponse(response = TestA.class, code = 200, message = "sfsfsfs")
	public List<TestA> test(@RequestBody() TestA testA) {
//		if (testA.getId() != 100)
//			throw new RuntimeException();
		List<TestA> list = new ArrayList<TestA>();
		list.add(testA);
		return list;
	}
	@GetMapping("/testA")
	@ApiOperation(value = "add-testA")
	@ApiResponse(response = TestA.class, code = 200, message = "sfsfsfs")
	public Object test2(@ApiParam() TestA testA) {
		return testA;
	}
	@GetMapping("/testB")
	@ApiOperation(value = "add-testA")
	@ApiResponse(response = TestA.class, code = 200, message = "sfsfsfs")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "testA", value = "参数A"),
		@ApiImplicitParam(name = "testB", value = "参数B"),
		@ApiImplicitParam(name = "testC", value = "参数C")
		})
	public Object test3(String testA, String testB, String testC) {
		return testA + " : " + testB + " : " + testC;
	}
	
	
	@GetMapping("/test4")
	@ApiOperation(value = "test4")
	public Object test4() {
		logger.debug("is debug info.........");
		logger.info("is info ....");
		logger.error("is error info......");
		return null;
	}
	
	@GetMapping("/test-date")
	@ApiOperation(value = "test-date")
	public Object testDate(@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-hh HH:mm:ss");
		System.out.println(sdf.format(new Date()));
		return sdf.format(date);
	}
	// localhost:8081/test/zk
	@RequestMapping("/zk")
	public String zk(String km2) {
		System.out.println(km2);
		return "";
	}
}
